package com.pms.controller;

import com.pms.dto.OwnerPageQueryDTO;
import com.pms.dto.OwnerSaveDTO;
import com.pms.dto.OwnerUpdateDTO;
import com.pms.result.PageResult;
import com.pms.result.Result;
import com.pms.service.OwnerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "业主相关接口")
@RestController
@RequestMapping("/owner")
@Slf4j
public class OwnerController {

    @Autowired
    private OwnerService ownerService;

    @ApiOperation("新增业主")
    @PostMapping("/save")
    public Result<String> save(@RequestBody OwnerSaveDTO ownerSaveDTO){
        log.info("新增业主,{}",ownerSaveDTO);
        ownerService.save(ownerSaveDTO);
        return Result.success();
    }

    @ApiOperation("业主分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(OwnerPageQueryDTO ownerPageQueryDTO){
        log.info("业主分页查询,{}",ownerPageQueryDTO);
        PageResult pageResult=ownerService.page(ownerPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("根据id批量删除")
    @DeleteMapping("/delete")
    public Result<String> delete(@RequestParam List<Integer> ids){
        log.info("根据id批量删除,{}",ids);
        ownerService.deleteBatch(ids);
        return Result.success();
    }

    @ApiOperation("修改业主信息")
    @PutMapping("/update")
    public Result<String> update(@RequestBody OwnerUpdateDTO ownerUpdateDTO){
        log.info("修改业主信息,{}",ownerUpdateDTO);
        ownerService.update(ownerUpdateDTO);
        return Result.success();
    }
}
